import argparse
import csv, math, os

LenPerLine = 70

parse = argparse.ArgumentParser()
parse.add_argument('-file', type=str, default='None', help="specify the path of upload csv file")
parse.add_argument('-gene', type=str, default='-', help='gene id or gene name')
parse.add_argument('-species', type=str, default='-', help='specify the species')
parse.add_argument('-fprimer', type=str, default='-', help='the forward primer sequence')
parse.add_argument('-rprimer', type=str, default='-', help='the reverse primer sequence')
parse.add_argument('-describe', type=str, default='-', help='description of the sequence')
parse.add_argument('-location', type=str, default='-', help='the locaion of the sequence')
parse.add_argument('-id', type=str, default='-', help='the identifier of the sequence')

args = parse.parse_args()
uploadfile = args.file
gene = args.gene
species = args.species
fprimer = args.fprimer
rprimer = args.rprimer
describe = args.describe
location = args.location
identifier = args.id

os.makedirs('D:/wamp64/www/primer/Public/db/', exist_ok=True)

with open('D:/wamp64/www/primer/Public/db/blast.fasta', 'a') as f:
    length = len(fprimer)
    f.writelines('>'+identifier+' gene='+gene+'\n')
    if(length<=LenPerLine):
        f.writelines(fprimer+'\n')
    else:
        for i in range(int(math.ceil(length/LenPerLine))):
            f.writelines(fprimer[i*LenPerLine:(i+1)*LenPerLine]+'\n')

os.system("makeblastdb -in D:/wamp64/www/primer/Public/db/blast.fasta -dbtype nucl -title sysuBlastDb -parse_seqids -out D:/wamp64/www/primer/Public/db/zfea_lncRNA/zfea_lncRNA")
